﻿using System;

namespace Sting
{
    class Program
    {
        static void Main(string[] args)
        {
            //DateTime类
            /* Console.WriteLine("Hello World!");
             DateTime dateTime = DateTime.Now;
             Console.WriteLine("当前日期为：{0}",dateTime );
             Console.WriteLine("当前时本月的第{0}天：",dateTime .Day );
             Console.WriteLine("当前时：{0}",dateTime .DayOfWeek);
             Console.WriteLine("当前是本年度第{0}天",dateTime .DayOfYear);
             Console.WriteLine("10天后的日期是{0}",dateTime .AddDays(10));

             Console.WriteLine();
             */
            // var currentTime = DateTime.Now;
            // Console.WriteLine(currentTime .ToString("yyy-MM-dd hh:mm:ss"));

            //获取字符串长度（string.length)
            /* string str = Console.ReadLine();
             Console.WriteLine("字符串的长度为："+str.Length );
             Console.WriteLine("字符串的第一个字符为：" + str [0]);
             Console.WriteLine("字符串中最后一个字符串："+ str [str.Length -1]);*/

            /* string str = Console.ReadLine();
             for (int i=str.Length -1;i>=0;i--)
             {
                 Console.WriteLine(str [i]);
             }*/
            //例子二
            /* var str2 = "字符串的使用";
             var id2 = str2.IndexOf("串");
             Console.WriteLine(id2 );
             Console.WriteLine(str2.LastIndexOf("的"));
             Console.WriteLine();*/

            //例子四
            /*  string str = Console.ReadLine();
              if (str.IndexOf("@") != -1)
              {
                  Console.WriteLine("字符串中含有@, 其出现的位置为{ 0}",
                      str.IndexOf("@") +1);
              }
              else
              {
                  Console.WriteLine("字符串中不含有@");
              }*/
            //例子五
            /*string str = Console.ReadLine();
            int firstIndex = str.IndexOf("@");
            int lastIndex = str.LastIndexOf("@");
            if(firstIndex !=-1)
            {
                if (firstIndex ==lastIndex )
                {
                    Console.WriteLine("在该字符串中仅有一个@");
                }
                else
                {
                    Console.WriteLine("在该字符串中有多个@");
                }
            }
            else
            {
                Console.WriteLine("在字符中没有@");
            }*/

            //Replace字符串替换涵
            /* string str = Console.ReadLine();
             if(str.IndexOf(",") !=-1)
             {
                 str = str.Replace(",", "_");
             }
             Console.WriteLine("替换后的字符串为："+str );*/

            /*var str1 = "中华人民共和国广西首府";
            var indexStr = str1.IndexOf("共");
            Console.WriteLine(indexStr);
            Console.WriteLine(str1.LastIndexOf("共"));
            Console.WriteLine(str1 .IndexOf ("六"));
            var  str2= str1.Replace("共","共共");
            Console.WriteLine(str2);*/

            //Substring :字符串截取函数
            /*   string str = Console.ReadLine();
              int firstIndex = str.IndexOf("@");
               int lastIndex = str.LastIndexOf("@");
               if(firstIndex !=-1 && firstIndex ==lastIndex)
               {
                   str = str.Substring(0, firstIndex);
               }
               Console.WriteLine("邮箱中的名字为："+str );


               var str2 = "中华人民共和国广西";
               var str3 = str2.Substring(5);
               Console.WriteLine(str3 );
               var str4 = str2.Substring(5, 3);
               Console.WriteLine(str4 );
               Console.WriteLine(str2 );
               */

            //Insert:字符串插入
           // string str = Console.ReadLine();
            //str = str.Insert(10, "@@@");
           // Console.WriteLine("新的字符串为："+str );

            var  str1 = "广西壮族自治区梧州市,藤县";
            var  insertStr = "123";
            //找到最后一个{、}的位置，然后插入字符
            var  result = str1.Insert(str1.LastIndexOf(","), insertStr);
            Console.WriteLine(result);
            Console.WriteLine();

        }
    }
}
